MkNode
:fa-brands-github: Show source on GitHub
Base class for everything which can be expressed as Markup.¶
Description
This class combines tree node functionality with markdown generation. Starting from the root nav (aka Docs) down to nested Markup blocks, the whole project can be represented by one tree.
MkNode is the base class for all nodes. We dont instanciate it directly.
All subclasses carry an MkAnnotations node (except the MkAnnotations node itself)
They can also pass an indent as well as a shift_header_levels keyword argument
in order to modify the resulting markdown.
__init__
¶
__init__(
*,
header: str = "",
indent: str = "",
name: str | None = None,
shift_header_levels: int = 0,
variables: dict[str, Any] | None = None,
context: ProjectContext | None = None,
parent: MkNode | None = None,
**_kwargs: Any
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
header
|
str
|
Optional header for contained Markup |
''
|
indent
|
str
|
Indentation of given Markup (unused ATM) |
''
|
name
|
str | None
|
An optional unique identifier (allows getting node via MkNode.get_node) |
None
|
shift_header_levels
|
int
|
Regex-based header level shifting (adds/removes #-chars) |
0
|
variables
|
dict[str, Any] | None
|
Variables to use for rendering |
None
|
context
|
ProjectContext | None
|
Context this Nav is connected to. |
None
|
parent
|
MkNode | None
|
Parent for building the tree |
None
|
add_css_class
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name
|
str
|
CSS class to wrap the node with |
required |
add_file
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Filename of the file to add |
required |
data
|
str | bytes
|
Data of the file |
required |
attach_annotations
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Markdown to annote |
required |
attach_css_classes
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Markdown to annote |
required |
is_descendant_of
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kls
|
type | UnionType
|
The class (union) the check the ancestors for |
required |
iter_nodes
¶
iter_nodes(indent: int = 0, max_depth: int | None = None) -> Iterator[tuple[int, MkNode]]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int
|
The start "level". The first element of the returned tuple will be relative to this |
0
|
max_depth
|
int | None
|
The max depth to iterate |
None
|
to_child_node
¶
to_child_node(other: str | list[Any] | MkNode | None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
str | list[Any] | MkNode | None
|
The node / string to convert to a child node. |
required |
to_html
¶
to_html(flavor: str | Renderer | None = None) -> str
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flavor
|
str | Renderer | None
|
Markdown flavour (renderer name like |
None
|
to_markdown
¶
to_markdown(flavor: str | Renderer | None = None) -> str
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flavor
|
str | Renderer | None
|
Markdown flavour (renderer name like |
None
|
with_context
classmethod
¶
| Name | Children | Inherits |
|---|---|---|
| MkContainerBase mknodes.basenodes.mkcontainer Abstract base class for nodes containing other MkNodes. |
||
| MkCompactAdmonition mknodes.basenodes.mkcompactadmonition Compact admonition info box. |
||
| MkLink mknodes.basenodes.mklink A simple Link (with optional icon and option to show up as a button). |
||
| MkText mknodes.basenodes.mktext Class for any Markup text. |
||
| MkHeader mknodes.basenodes.mkheader Super simple header node. |
||
| MkKeys mknodes.basenodes.mkkeys Node to display Keyboard keys. |
||
| MkDocStrings mknodes.basenodes._mkdocstrings Docstring section (powered by mkdocstrings). |
||
| MkIcon mknodes.basenodes.mkicon Pyconify-based Icon. |
||
| MkImage mknodes.basenodes.mkimage Image including optional caption. |
||
| MkProgressBar mknodes.basenodes.mkprogressbar Node to display a CSS-based progress bar. |
||
| BaseBlock mknodes.pages.templateblocks A class representing a block from a page template. |
||
| MkTimelineItem mknodes.basenodes.mktimeline Single Timeline item / card. |
||
| MkPyodideTerminal mknodes.basenodes.mkpyodide Node for embedding a Pyodide terminal running Python code. |
||
| MkJupyterLite mknodes.basenodes.mkjupyterlite Node for embedding a JupyterLite RetroLab interface. |
||
| MkPyScript mknodes.basenodes.mkpyscript Node for embedding a PyScript terminal. |
||
| MkDataClassInfo mknodes.basenodes.mkdataclassinfo Node for displaying dataclass-like object information. |
||
| MkNav mknodes.navs.mknav Nav section, representing a nestable menu. |
||
| MkTemplateTable mknodes.templatenodes.mktemplatetable Node for a table showing dependencies for a package. |
||
| MkPyDeps mknodes.templatenodes.mkpydeps Node for showing a Dependency graph. |
||
| FlavorComparison mknodes.manual.flavors Markdown of a node in the Material and the GitHub flavour, side by side. |